import roslibpy

class SetSwingDuration:

    def __init__(self, framework):
        self.framework = framework
        self.talker = None
        self.swing_duration = 0.16

    def set(self, swing_duration):
        if self.framework.framework.utils.device.device_state:
            self.swing_duration = swing_duration
            self.talker = roslibpy.Topic(self.framework.framework.utils.device.device_connect, "/alphadog_node/set_swing_duration", "ros_alphadog/SetSwingDuration")
            self.talker.publish(roslibpy.Message({"swing_duration": self.swing_duration}))
            self.end()

    def end(self):
        self.swing_duration = 0.16
